package com.example.jpetstoreclient.service.impl;

import com.example.jpetstoreclient.service.EmailService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service("emailService")
public class EmailServiceImpl implements EmailService {
    @Resource
    private JavaMailSender sender;
    @Value("${spring.mail.username}")
    private String email;

    @Override
    public void sendVerifyCode(String mail, String code) {
        SimpleMailMessage message = new SimpleMailMessage();
        //邮件标题
        message.setSubject("【JPetStore】您的验证码");
        //邮件内容
        message.setText("您的验证码是：" + code);
        //谁发送，必须和配置文件中的账号一致
        message.setFrom(email);
        //谁接收
        message.setTo(mail);
        sender.send(message);
    }
}
